{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content"> 
				<div class="row row-lg"> 
					<div class="col-sm-12"> 
						<div class="row" id="searchGroup">
							<!-- search end -->
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
						{if condition="in_array('admin/Test/add',session('admin.nodes')) || session('admin.role_id') eq 1"}
						<button type="button" id="add" class="btn btn-primary button-margin" onclick="CodeGoods.add()">
						<i class="fa fa-plus"></i>&nbsp;添加
						</button>
						{/if}
						{if condition="in_array('admin/Test/update',session('admin.nodes')) || session('admin.role_id') eq 1"}
						<button type="button" id="update" class="btn btn-success button-margin" onclick="CodeGoods.update()">
						<i class="fa fa-pencil"></i>&nbsp;修改
						</button>
						{/if}
						{if condition="in_array('admin/Test/delete',session('admin.nodes')) || session('admin.role_id') eq 1"}
						<button type="button" id="delete" class="btn btn-danger button-margin" onclick="CodeGoods.delete()">
						<i class="fa fa-trash"></i>&nbsp;删除
						</button>
						{/if}
						{if condition="in_array('admin/Test/view',session('admin.nodes')) || session('admin.role_id') eq 1"}
						<button type="button" id="view" class="btn btn-info button-margin" onclick="CodeGoods.view()">
						<i class="fa fa-eye"></i>&nbsp;查看详情
						</button>
						{/if}
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '学号', field: 'student_num', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '联系电话', field: 'tel', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '年级', field: 'grade', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '专业', field: 'major', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '班级', field: 'class', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '就业方向', field: 'g_des', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位/学校名称', field: 'u_name', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位性质', field: 'u_nature', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位行业', field: 'u_vocation', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '工作职位类别', field: 'u_positiion', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '组织机构代码', field: 'o_daima', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位所在地（省）', field: 'u_location1', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位所在地（市）', field: 'u_location2', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位所在地（县）', field: 'u_location3', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位所在地（精确到门派号）', field: 'u_address', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位邮编', field: 'u_p_c', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位是否接受档案', field: 'u_dangan', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.u_danganFormatter},
 			{title: '接收档案单位名称', field: 'rd_unitname', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '接收档案单位邮编', field: 'd_unitp_c', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '档案转寄单位所在地（省）', field: 'd_unitaddr1', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '转寄单位所在地（市）', field: 'd_unitaddr2', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '档案转寄单位所在地（县）', field: 'd_unitaddr3', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '档案转寄单位所在地（精确到门派号）', field: 'd_unitaddr4', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位联系人', field: 'u_lingkman', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '单位联系人电话', field: 'linkman_tel', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '报到证单位名称', field: 'bq_unitname', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '报到证单位所在地（省）', field: 'bq_unitaddr1', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '报到证单位所在地（市）', field: 'bq_unitaddr2', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '报到证单位所在地（县）', field: 'bq_unitaddr3', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: 'user_id', field: 'user_id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '三方协议或就业合同照片', field: 'file', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.fileFormatter},
 			{title: '操作', field: '', visible: true, align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 		];
 	};

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(row.id){
			var str= '';
			{if condition="in_array('admin/Test/update',session('admin.nodes')) || session('admin.role_id') eq 1"}
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+row.id+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;';
			{/if}
			{if condition="in_array('admin/Test/delete',session('admin.nodes')) || session('admin.role_id') eq 1"}
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+row.id+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;';
			{/if}
			return str;
		}
	}

	CodeGoods.u_danganFormatter = function(value,row,index) {
		if(value !== null){
			if(value == 1){
				return '<input class="mui-switch mui-switch-animbg u_dangan'+row.id+'" type="checkbox" onclick="CodeGoods.updateu_dangan('+row.id+',0,\'u_dangan\')" checked>';
			}else{
				return '<input class="mui-switch mui-switch-animbg u_dangan'+row.id+'" type="checkbox" onclick="CodeGoods.updateu_dangan('+row.id+',1,\'u_dangan\')">';
			}
		}
	}


	CodeGoods.updateu_dangan = function(pk,value,field) {
		var ajax = new $ax(Feng.ctxPath + "/Test/updateExt", function (data) {
			if ('00' !== data.status) {
				Feng.error(data.msg);
				$("."+field+pk).prop("checked",!$("."+field+pk).prop("checked"));
			}
		});
		var val = $("."+field+pk).prop("checked") ? 1 : 0;
		ajax.set('id', pk);
		ajax.set('u_dangan', val);
		ajax.start();
	}

	CodeGoods.fileFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";	
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['offset'] = 0;
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.add = function (value) {
		var url = location.search;
		var index = layer.open({type: 2,title: '添加',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Test/add'+url});
		this.layerIndex = index;
		if(!IsPC()){layer.full(index)}
	}


	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Test/update?id='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '修改',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Test/update?id='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}


	CodeGoods.delete = function (value) {
		if(value){
			Feng.confirm("是否删除选中项？", function () {
				var ajax = new $ax(Feng.ctxPath + "/Test/delete", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('id', value);
				ajax.start();
			});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				Feng.confirm("是否删除选中项？", function () {
					var ajax = new $ax(Feng.ctxPath + "/Test/delete", function (data) {
						if ('00' === data.status) {
							Feng.success(data.msg,1000);
							CodeGoods.table.refresh();
						} else {
							Feng.error(data.msg,1000);
						}
					});
					ajax.set('id', idx);
					ajax.start();
				});
			}
		}
	}


	CodeGoods.view = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Test/view?id='+value});
			if(!IsPC()){layer.full(index)}
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '查看详情',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Test/view?id='+idx});
				this.layerIndex = index;
				if(!IsPC()){layer.full(index)}
			}
		}
	}


	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/Test/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
</script>
{/block}